<?php

/**
 * Description of userLoginDoAction
\* www.teuker.nl - mail@teuker.nl
 * 
 * @author francisc
 */

class userLoginDoAction extends sfAction {

    public function execute($request) {
        Util::loadI18NHelper();

        $user = SqlEngine::getUser(array('password' => $request->getParameter('password'),
                                         'username' => $request->getParameter('username')));

        if (empty($user)) {
            $this->getUser()->setFlash('message', __('Incorrect username/password or the user does not exist in the system'));
            $this->setTemplate('userLogin');
        }
        else {
            $this->getUser()->setAttribute('user_type', $user[0]['user_type']);
            $this->getUser()->setAttribute('user_namefirst', $user[0]['name_first']);
            $this->getUser()->setAttribute('user_namelast', $user[0]['name_last']);
            $this->getUser()->setAttribute('console', $user[0]['receive_console_messages']);
            $this->getUser()->setAttribute('user_id', $user[0]['user_id']);
            
            return $this->redirect('@login_user_home');
        }
    }
}
